package elitech.vietnam.copyweatherfashion.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.URLUtil;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;

import elitech.vietnam.copyweatherfashion.R;
import elitech.vietnam.copyweatherfashion.libs.zoomimage.ImageViewTouchBase.DisplayType;
import elitech.vietnam.copyweatherfashion.widget.ZoomImageView;

public class ZoomPagerItemFragment extends Fragment {

	private ZoomImageView	image;
	private String			link;

	public static ZoomPagerItemFragment newInstance(String link) {
		ZoomPagerItemFragment fragment = new ZoomPagerItemFragment();
		Bundle bundle = new Bundle();
		bundle.putString("LINK", link);
		fragment.setArguments(bundle);
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		link = getArguments().getString("LINK");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.layout_zoompager, container, false);

		image = (ZoomImageView) view.findViewById(R.id.zoom_image);
		image.setDisplayType(DisplayType.FIT_TO_SCREEN);
		
		return view;
	}

	@Override
	public void onStart() {
		super.onStart();
		if (link != null && URLUtil.isValidUrl(link))
			UrlImageViewHelper.setUrlDrawable(image, link);
	}
}